define(['jquery', 'vue', 'common'],function ($, Vue, common){
    var Controller = {
        index: function () {
            const {createApp, ref, onMounted} = Vue
            const app = createApp({
                setup(){
                    const list = ref({
                        total:0,
                        rows:[],
                        seachObj:[
                            {
                                name:"order",
                                value:"desc",
                                is_show:false
                            },
                            {
                                name:"sort",
                                value:"createtime",
                                is_show:false
                            },
                            {
                                label:"ID",
                                name:"id",
                                value:"",
                                type:"input",
                                is_show:true,
                            },
                            {
                                label:"用户名",
                                name:"username",
                                value:"",
                                seach_type:"LIKE",
                                type:"input",
                                is_show:true
                            },
                            {
                                label:"操作页面",
                                name:"url",
                                value:"",
                                seach_type:"LIKE",
                                type:"input",
                                is_show:true
                            },
                            {
                                label:"IP地址",
                                name:"ip",
                                value:"",
                                seach_type:"LIKE",
                                type:"input",
                                is_show:true
                            }
                        ],
                        page:1,
                        limit:10
                    })
                    const getIndex = ()=>{
                        common.loadingIndexData(list.value).then(res=>{
                            if(res.code==1){
                                list.value.rows = res.data.rows
                                list.value.total = res.data.total
                            }
                        })
                    }
                    onMounted(()=>{
                        getIndex()
                    })
                    common.refresh = ()=>{
                        getIndex()
                    }
                    common.changePage = (page)=>{
                        list.value.page = page
                        getIndex()
                    }
                    common.changeSize = (size)=>{
                        list.value.limit = size
                        getIndex()
                    }
                    common.reset = ()=>{
                        let seachObj = list.value.seachObj
                        seachObj.forEach(item=>{
                            if(item.is_show===true){
                                item.value = ""
                            }
                        })
                        // console.log(seachObj);
                        getIndex()
                    }
                    return {
                        list,
                        common:common
                    }
                }
            })
            common.load(app)
            app.mount('#app')
        }
    }
    return Controller
})